<template>
  <div>
    <Header></Header>
    <div class="block">
      <el-timeline>
        <el-timeline-item :timestamp="blog.created" placement="top" v-for="blog in blogs">
          <el-card>
            <router-link :to="{name: 'BlogDetail', params: {blogId: blog.id}}">
              <h4>{{blog.title}}</h4>
            </router-link>
            <p>{{blog.description}}</p>
          </el-card>
        </el-timeline-item>
      </el-timeline>
      <el-pagination class="mpage"
          background
          layout="prev, pager, next"
          :current-page="currentPage"
                     :page-size="pageSize"
          :total="total"
                     @current-change=page
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import Header from "@/components/Header";
export default {
  name: "Blog",
  components: {
    Header
  },
  data() {
    return {
      blogs: [],
      currentPage:1,
      total: 0,
      pageSize: 5,
    }
  }
  ,
  methods: {
    page(currentPage) {
      this.$axios.get("/blogs?currentPage=" + currentPage).then(res=>{
        //console.log(res.data);
        this.blogs = res.data.data.records;
        this.currentPage = res.data.data.current;
        this.total = res.data.data.total;
        this.pageSize = res.data.data.size;
      })
    }
  },
  mounted() {
    this.page(1);
    //console.log(this.blogs);
  }
}
</script>

<style scoped>
  .mpage{
    margin: 0 auto;
    text-align: center;
  }


</style>